<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends CommonController
{

    public function main()
    {


        $this->display('index/main');
    }

//    public function admin_add()
//    {
//
//        $this->display('index/admin_add');
//    }

    public function df1()
    {

        $year = date("Y");
        $month = date("m");
        $day = date("d");
        $dayed = date("d") - 1;
        $dayBegin = mktime(0, 0, 0, $month, $day, $year);//当天开始时间戳
        $dayEnd = mktime(23, 59, 59, $month, $day, $year);//当天结束时间戳

        $dayBegined = mktime(0, 0, 0, $month, $dayed, $year);//当天开始时间戳
        $dayEnded = mktime(23, 59, 59, $month, $dayed, $year);//当天结束时间戳

        $startTime = date('Y-m-d H:i:s', $dayBegin);
        $endTime = date('Y-m-d H:i:s', $dayEnd);

        $startTimed = date('Y-m-d H:i:s', $dayBegined);
        $endTimed = date('Y-m-d H:i:s', $dayEnded);
        //echo $endTimed;die;
        //今天註冊會員
        $zt = M('system')->where(array('SYS_ID' => 1))->find();
        // 		$time2 = date('H');
        $this->zt = $zt;


        $ip = M('drrz')->where(array('user' => $_SESSION ['adminuser'], 'leixin' => 1))->order('id DESC')->limit(2)->select();

        $this->bcip = $ip[0];
        $this->scip = $ip[1];
        $this->jtzchy = M('user')->where("`UE_regTime`> '" . $startTime . "' AND `UE_regTime` < '" . $endTime . "'")->count("UE_ID");

        //今天激活會員
        $this->jtjhhy = M('user')->where("`UE_activeTime`> '" . $startTime . "' AND `UE_activeTime` < '" . $endTime . "'")->count("UE_ID");

        //昨天註冊會員
        $this->ztzchy = M('user')->where("`UE_regTime`> '" . $startTimed . "' AND `UE_regTime` < '" . $endTimed . "'")->count("UE_ID");

        //昨天激活會員
        $this->ztjhhy = M('user')->where("`UE_activeTime`> '" . $startTimed . "' AND `UE_activeTime` < '" . $endTimed . "'")->count("UE_ID");


        //總會員
        $this->zuser = M('user')->where("`UE_ID`> '0'")->count("UE_ID");

        //總激活會員
        $this->zjhuser = M('user')->where("`UE_ID`> '0' AND `UE_check` = '1'")->count("UE_ID");

        //總出局會員
        $this->zcjuser = M('user')->where("`UE_ID`> '0' AND `UE_check` = '1' AND `UE_stop` = '0'")->count("UE_ID");

        //總金幣
        $this->zjb = M('user')->sum('UE_money');

        //總銀幣
        $this->zyb = M('user')->sum('ybhe');

        //總鑽石幣
        $this->zzsb = M('user')->sum('zsbhe');


        $this->display('index/index');
    }

//    public function gb()
//    {
//
//
//        M('system')->where(array('SYS_ID' => 1))->save(array('zt' => 1));
//        // 		$time2 = date('H');
//        $this->success('关闭成功!');
//
//
//    }

//    public function kq()
//    {
//
//
//        M('system')->where(array('SYS_ID' => 1))->save(array('zt' => 0));
//        // 		$time2 = date('H');
//        $this->success('开启成功!');
//
//
//    }

//    public function top()
//    {
//        $this->display('index/top');
//    }

    public function team()
    {
        $this->user = I('get.user', '0');
        $this->display('index/team');
    }

//    public function left()
//    {
//        $this->display('index/left');
//    }

    public function user_xg()
    {
        $id=I('get.id');
        if($id<>""){
            $this->userdata =M('user')->where(array('UE_ID'=>$id))->find();
            $this->display('index/user_xg');
        }
        else{
            $this->error('非法操作!');
        }
//        if (I('get.user') <> '') {
//            $this->userdata = M('user')->where(array('UE_account' => I('get.user')))->find();
//            $this->display('index/user_xg');
//        } else {
//
//        }
    }

    public function admin_xg()
    {
        if (I('get.user') <> '') {
            $this->userdata = M('member')->where(array(
                'MB_username' => I('get.user')
            ))->find();
            $this->display('index/admin_xg');
        } else {
            $this->error('非法操作!');
        }
    }

    public function usercl()
    {

        //dump(I('post.'));
        $data['UE_check'] = I('post.UE_check');
        $data['sfjl'] = I('post.UE_stop');
        $data['UE_status'] = I('post.ue_status');
        if (I('post.UE_password') <> '') {
            $data['UE_password'] = md5(I('post.UE_password'));
        }
        if (I('post.UE_secpwd') <> '') {
            $data['UE_secpwd'] = md5(I('post.UE_secpwd'));
        }
//        $data['UE_truename'] = I('post.UE_truename');
//        $data['UE_sfz'] = I('post.UE_sfz');
//        $data['email'] = I('post.email');

        $tj=I('post.ue_accname');
        $tj_info=M('user')->where(array('UE_account'=>$tj))-> find();
//        dump($tj_info);
        if(empty($tj_info)){
            msg('推荐人不存在');
//            die("<script>alert('激活码数量不足，无法提供帮助！');history.back(-1);</script>");
//            $this->success('推荐人不存在！!');
        }
        $data['UE_accName'] =$tj;
        $data['UE_phone'] = I('post.UE_phone');
        $data['UE_truename'] = I('post.UE_truename');
        $data['user_bankcard'] = I('post.user_bankcard');
        $data['user_bankname'] = I('post.user_bankname');
        $data['user_bankuser'] = I('post.user_bankuser');
        $data['user_bankaddress'] = I('post.user_bankaddress');

//        $data['UE_theme'] = I('post.UE_theme');
        // dump(I('post.UE_account'));die;
        if (M('user')->where(array('UE_account' => I('post.UE_account')))->save($data)) {
            $this->success('修改成功!');
        } else {
//            dump(M('user')->getLastSQL());
            $this->success('修改失败!');
        }
    }
    
    public function admincl()
    {


        $data['MB_right'] = I('post.MB_right');
        if (I('post.MB_userpwd') <> '') {
            $data['MB_userpwd'] = md5(I('post.MB_userpwd'));
        }
        //dump($data);die;
        if (M('member')->where(array('MB_username' => I('post.MB_username')))->save($data)) {
            $this->success('修改成功!', U('Index/adminlist'));
        } else {
            $this->success('修改失败!');
        }
    }
    
    public function adminadd()
    {


        $data['MB_username'] = I('post.MB_username');
        $data['MB_right'] = I('post.MB_right');
        $data['MB_userpwd'] = md5(I('post.MB_userpwd'));
        if (I('post.MB_username') <> '' && I('post.MB_right') <> '' && I('post.MB_userpwd') <> '') {
            //dump($data);die;
            if (M('member')->add($data)) {
                $this->success('添加成功!', U('Index/adminlist'));
            } else {
                $this->success('添加失败!');
            }
        } else {
            $this->success('数据不能为空!');
        }
    }
    
    public function userlist()
    {


        $User = M('user'); // 實例化User對象
        $data = I('post.user');
        $par=array();
        $username=gpc('username');
        //$map ['UG_dataType'] = array('IN',array('mrfh','tjj','kdj','mrldj','glj'));

        if ($data <> '') {
            $map['UE_account'] = $data;
        }
        if(IS_POST && empty($username)){
            session('u_username',null);
        }
        if($username!=""){

            $map["user_bankuser"] = array('like', "%$username%");
            session('u_username',$username);
        }else{
            if(!empty(session('u_username')) && session('u_username')!=""){
                $map["user_bankuser"] = array('like', "%".session('u_username')."%");
            }

        }
        $order=gpc('order');
        if($order>0)
        {
            $map['user_latematch'] = $order;

            $par['order']=$order;
            $this->assign('order',$order);
        }
        $num=gpc('num');
        if($num>0){
            $db_match = M('matching');
            $m_info = $db_match->order('mc_id desc')->limit(1)->select()[0];
            $map['user_latematch'] = array('elt',$m_info['mc_order']-$num);
            $par['num']=$num;
            $this->assign('num',$num);
        }
        if (I('get.ip') <> '') {
            $map['UE_regIP'] = I('get.ip');
        }
        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)

        $p = getpage($count, 20);

        $list = $User->where($map)->order('UE_ID')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('list', $list); // 賦值數據集
        $this->assign('page', $p->show()); // 賦值分頁輸出


        $mlist=M('matching')->select();

        $db_match = M('matching');
        $m_info = $db_match->order('mc_id desc')->limit(1)->select()[0];

        $this->assign('m_info',$m_info);
        $this->assign('mlist',$mlist);


        $this->display('index/userlist');
    }


    public function dis_list(){
        $User = M('user'); // 實例化User對象
        $data = I('post.user');
        $par=array();
        $username=gpc('username');
        //$map ['UG_dataType'] = array('IN',array('mrfh','tjj','kdj','mrldj','glj'));

        if ($data <> '') {
            $map['UE_account'] = $data;
        }

        if($username!=""){

            $map["user_bankuser"] = array('like', "%$username%");
        }

        $order=gpc('order');
        if($order>0)
        {
            $map['user_latematch'] = $order;

            $par['order']=$order;
            $this->assign('order',$order);
        }
        $num=gpc('num');
        if($num>0){
            $db_match = M('matching');
            $m_info = $db_match->order('mc_id desc')->limit(1)->select()[0];
            $map['user_latematch'] = array('elt',$m_info['mc_order']-$num);
            $par['num']=$num;
            $this->assign('num',$num);
        }
        if (I('get.ip') <> '') {
            $map['UE_regIP'] = I('get.ip');
        }
        $map['UE_status']=1;
        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)

        $p = getpage($count, 20);

        $list = $User->where($map)->order('UE_ID')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('list', $list); // 賦值數據集
        $this->assign('page', $p->show()); // 賦值分頁輸出


        $mlist=M('matching')->select();

        $db_match = M('matching');
        $m_info = $db_match->order('mc_id desc')->limit(1)->select()[0];

        $this->assign('m_info',$m_info);
        $this->assign('mlist',$mlist);


        $this->display('index/userlist');
    }

    public function adminlist()
    {

    is_qx(1);
        $User = M('member'); // 實例化User對象
        $data = I('post.user');


        //$map ['UG_dataType'] = array('IN',array('mrfh','tjj','kdj','mrldj','glj'));

        if ($data <> '') {
            $map['MB_username'] = $data;
        }

        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)

        $p = getpage($count, 20);

        $list = $User->where($map)->order('MB_ID')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('list', $list); // 賦值數據集
        $this->assign('page', $p->show()); // 賦值分頁輸出


        $this->display('index/adminlist');
    }
    public function unblock(){

        is_qx(1);
        $User = M('user');
        $data = I('get.id');
        $userxx = M('user')->where(array('UE_ID' => $data))->find();
        if(empty($userxx)){$this->success('该用户不存在！');}

        if ($data <> '' && $userxx['ue_account'] <> '') {
            M('user')->where(array('UE_ID' => $data))->save(array('UE_status'=>0));
            $this->success('解封成功！!');
        }else{
            $this->success('公司账号不能删除!');
        }

    }
    public function js_setstatus(){

        $id=gpc('id');

        $db_tg=M('jsbz');
        $tg_info=$db_tg->where(array('id'=>$id))->find();
        if(empty($tg_info)){echo '错误';}

        $status=$tg_info['js_status'];
        switch ($status){
            case 0:
                $db_tg->where(array('id'=>$id))->save(array('js_status'=>1));
                echo "0";
                break;
            case 1:
                $db_tg->where(array('id'=>$id))->save(array('js_status'=>0));
                echo "1";
                break;
        }
    }
    public function tg_setstatus(){

        $id=gpc('id');

        $db_tg=M('tgbz');
        $tg_info=$db_tg->where(array('id'=>$id))->find();
        if(empty($tg_info)){echo '错误';}

        $status=$tg_info['tg_status'];
        switch ($status){
            case 0:
                $db_tg->where(array('id'=>$id))->save(array('tg_status'=>1));
                echo "0";
                break;
            case 1:
                $db_tg->where(array('id'=>$id))->save(array('tg_status'=>0));
                echo "1";
                break;
        }
    }
    //删除用户
    public function userdel()
    {
        is_qx(1);
        $User = M('user'); // 實例化User對象
        $data = I('get.id');
        $userxx = M('user')->where(array('UE_ID' => $data, 'UE_check' => '0'))->find();

        if ($data <> '' && $userxx['ue_account'] <> '') {
            M('user')->where(array('UE_ID' => $data, 'UE_check' => '0'))->delete();
            $this->success('删除成功!');
        } else {
            $this->success('公司账号不能删除!');
        }
    }

    //删除交易订单
    public function ppdd_list_del()
    {

        is_qx(1);
        $User = M('user'); // 實例化User對象
        $data = I('get.id');


        $userxx = M('ppdd')->where(array('id' => $data))->find();

        if ($data <> '' && $userxx['id'] <> '') {
            M('ppdd')->where(array('id' => $data))->delete();
            M('tgbz')->where(array('id' => $userxx['p_id']))->delete();
            M('jsbz')->where(array('id' => $userxx['g_id']))->delete();
            $this->success('删除成功!');
        } else {
            $this->success('订单不存在!');
        }


    }

    //删除提供帮助
    public function tgbz_list_del()
    {

        is_qx(1);
        $User = M('user'); // 實例化User對象
        $data = I('get.id');


        $userxx = M('tgbz')->where(array('id' => $data))->find();

        if ($data <> '' && $userxx['id'] <> '') {

            M('tgbz')->where(array('id' => $userxx['id']))->delete();

            $this->success('删除成功!');
        } else {
            $this->success('订单不存在!');
        }


    }

    //删除接受帮助
    public function jsbz_list_del()
    {

        is_qx(1);
        $User = M('user'); // 實例化User對象
        $data = I('get.id');

        $userxx = M('jsbz')->where(array('id' => $data))->find();

        if ($data <> '' && $userxx['id'] <> '') {

            M('jsbz')->where(array('id' => $userxx['id']))->delete();

            $this->success('删除成功!');
        } else {
            $this->success('订单不存在!');
        }


    }

    public function admindel()
    {

        is_qx(1);
        $User = M('member'); // 實例化User對象
        $data = I('get.id');


        $userxx = M('member')->where(array('MB_ID' => $data))->find();

        if ($data <> '' && $userxx['mb_username'] <> '') {
            M('member')->where(array('MB_ID' => $data))->delete();
            $this->success('删除成功!',U('Index/adminlist'));
        } else {
            $this->success('不能删除!');
        }


    }
    
//    public function usermb()
//    {
//
//
//        $User = M('user'); // 實例化User對象
//        $data = I('get.id');
//
//
//        $userxx = M('user')->where(array('UE_ID' => $data))->find();
//
//        if ($data <> '' && $userxx['ue_account'] <> '') {
//            if (M('user')->where(array('UE_ID' => $data))->save(array('UE_question' => '', 'UE_question2' => '', 'UE_question3' => '', 'UE_answer' => '', 'UE_answer2' => '', 'UE_answer3' => ''))) {
//                $this->success('成功!');
//            } else {
//                $this->success('失败!');
//            }
//        } else {
//            $this->success('用户不存在!');
//        }
//
//
//    }


//    public function userbtc()
//    {
//
//
//        $User = M('user'); // 實例化User對象
//        $data = I('get.cz');
//
//
//        if ($data == 'n') {
//            $map['btbdz'] = '0';
//        } elseif ($data == 'y') {
//            $map['btbdz'] = array('neq', '0');
//        }
//        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
//        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)
//
//        $p = getpage($count, 20);
//
//        $list = $User->where($map)->order('UE_ID')->limit($p->firstRow, $p->listRows)->select();
//        $this->assign('list', $list); // 賦值數據集
//        $this->assign('page', $p->show()); // 賦值分頁輸出
//
//
//        $this->display('index/userbtc');
//    }


//    public function rggl()
//    {
//
//
//        $User = M('userjyinfo'); // 實例化User對象
//        $data = I('get.cz');
//
//
//        if ($data == 'n') {
//            $map['UJ_jbmcStage'] = '0';
//        } elseif ($data == 'y') {
//            $map['UJ_jbmcStage'] = '1';
//        }
//        $map['UJ_dataType'] = 'rg';
//
//        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
//        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)
//
//        $p = getpage($count, 20);
//
//        $list = $User->where($map)->order('UJ_ID')->limit($p->firstRow, $p->listRows)->select();
//        $this->assign('list', $list); // 賦值數據集
//        $this->assign('page', $p->show()); // 賦值分頁輸出
//
//
//        $this->display('index/rggl');
//    }
//
//    public function rggldel()
//    {
//
//
//        $data = I('get.id');
//
//
//        if ($data <> '') {
//            if (M('userjyinfo')->where(array('UJ_ID' => $data))->delete()) {
//                $this->success('删除成功');
//            } else {
//                $this->success('删除失败');
//            }
//        }
//    }
//
//
//    public function rgglsh()
//    {
//
//
//        $data = I('get.id');
//
//
//        if ($data <> '') {
//
//            $ddxx = M('userjyinfo')->where(array('UJ_ID' => $data))->find();
//
//            if ($ddxx['uj_style'] == 'rgzsb') {
//
//                M('user')->where(array('UE_account' => $ddxx['uj_usercount']))->setInc('zsbhe', $ddxx['uj_jbcount']);
//                $userxx = M('user')->where(array('UE_account' => $ddxx['uj_usercount']))->find();
//                $note3 = "原始鑽石幣購買";
//                $record3 ["UG_account"] = $ddxx['uj_usercount']; // 登入轉出賬戶
//                $record3 ["UG_type"] = 'zsb';
//                $record3 ["zsb"] = $ddxx['uj_jbcount']; // 金幣
//                $record3 ["zsb1"] = $ddxx['uj_jbcount']; //
//                $record3 ["zsbhe"] = $userxx['zsbhe']; // 當前推薦人的金幣餘額
//                $record3 ["UG_dataType"] = 'rg'; // 金幣轉出
//                $record3 ["UG_note"] = $note3; // 推薦獎說明
//                $record3["UG_getTime"] = date('Y-m-d H:i:s', time()); //操作時間
//                $reg4 = M('userget')->add($record3);
//                M('userjyinfo')->where(array('UJ_ID' => $data))->save(array('UJ_jbmcStage' => '1'));
//                $this->success('处理成功');
//
//            } elseif ($ddxx['uj_style'] == 'rgyb') {
//
//
//                M('user')->where(array('UE_account' => $ddxx['uj_usercount']))->setInc('ybhe', $ddxx['uj_jbcount']);
//                $userxx = M('user')->where(array('UE_account' => $ddxx['uj_usercount']))->find();
//                $note3 = "原始银幣購買";
//                $record3 ["UG_account"] = $ddxx['uj_usercount']; // 登入轉出賬戶
//                $record3 ["UG_type"] = 'yb';
//                $record3 ["yb"] = $ddxx['uj_jbcount']; // 金幣
//                $record3 ["yb1"] = $ddxx['uj_jbcount']; //
//                $record3 ["ybhe"] = $userxx['ybhe']; // 當前推薦人的金幣餘額
//                $record3 ["UG_dataType"] = 'rg'; // 金幣轉出
//                $record3 ["UG_note"] = $note3; // 推薦獎說明
//                $record3["UG_getTime"] = date('Y-m-d H:i:s', time()); //操作時間
//                $reg4 = M('userget')->add($record3);
//                M('userjyinfo')->where(array('UJ_ID' => $data))->save(array('UJ_jbmcStage' => '1'));
//                $this->success('处理成功');
//
//
//            }
//
//
//        }
//    }


    public function jbzs()
    {


        $User = M('userget'); // 實例化User對象


        $map['UG_dataType'] = 'xtzs';

        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)

        $p = getpage($count, 20);

        $list = $User->where($map)->order('UG_ID DESC')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('list', $list); // 賦值數據集
        $this->assign('page', $p->show()); // 賦值分頁輸出
        
        $this->display('index/jbzs');
    }


    public function userbtccl()
    {


        $User = M('user'); // 實例化User對象
        //dump(I('post.UE_ID'));die;
        if (I('post.UE_ID') <> '' && I('post.btbdz') <> '0') {
            if ($User->where(array('UE_ID' => I('post.UE_ID')))->save(array('btbdz' => I('post.btbdz')))) {
                $this->success('修改成功!');
            } else {
                $this->success('修改失败!');
            }
        } else {
            $this->success('您没修改内容!');
        }

    }

    //资金充减
    public function jbzscl()
    {

        is_qx(1);
        $User = M('user'); // 實例化User對象
        $where['UE_account'] = I('post.user');

        $num = gpc('sl');

        if (!preg_match('/^[0-9-]{1,20}$/',$num)) {
            $this->error('数量格式不对！');
        }

        $uinfo = $User->where($where)->find();
        if (empty($uinfo)) {
            $this->error('该会员不存在或填写有误！');
        }
        $record3 ["UG_account"] = I('post.user'); // 登入轉出賬戶
        $record3 ["UG_money"] = $num; // 金幣
        $record3 ["UG_allGet"] = $uinfo['ue_money']; //
        $record3 ["UG_dataType"] = 'xtzs'; // 金幣轉出
        $record3 ["UG_note"] = '系统操作'; // 推薦獎說明
        $record3["UG_getTime"] = date('Y-m-d H:i:s', time()); //操作時間

        $db_finance=M('userget');
        switch (I('post.lx')) {
            case 'jj'://R钱包 推荐奖
                $record3 ["UG_type"] = 'jb';
                $User->where($where)->setInc('UE_money', $num);
                $record3 ["UG_balance"] = $uinfo['ue_money'] + $num;
                $db_finance->add($record3);
                $this->success('R钱包充值成功!');
                break;
            case 'tj'://C钱包 推荐奖
                $record3 ["UG_type"] = 'tj';

                $User->where($where)->setInc('tj_he', $num);
                $record3 ["UG_balance"] = $uinfo['tj_he'] + $num;
                $db_finance->add($record3);
                $this->success('C钱包充值成功!');
                break;
            case 'jh'://激活码
                $record3 ["UG_type"] = 'jh';
                $User->where($where)->setInc('user_jhb', $num);
                $record3 ["UG_balance"] = $uinfo['user_jhb'] + $num;
                $db_finance->add($record3);
                $this->success('激活币充值成功!');
                break;
        }

    }

//    public function tj_zrjj_cl()
//    {
//        header("Content-Type:text/html; charset=utf-8");
//
//        if (IS_POST) {
//
//            //时间
//            $NowTime = date('Y-m-d H:i:s', time());
//
//            $gxTime = $NowTime;//每日分紅的時間
//            //echo $gxTime;
//
//            $year = date("Y");
//            $month = date("m");
//            $day = date("d");
//
//            $dayBegin = mktime(0, 0, 0, $month, $day, $year);//當天開始時間戳
//            $dayEnd = mktime(23, 59, 59, $month, $day, $year);//當天結束時間戳
//
//            $startTime = date('Y-m-d H:i:s', $dayBegin);
//            $endTime = date('Y-m-d H:i:s', $dayEnd);
//
//            $startTimed = date('Y-m-d H:i:s', $dayBegin);
//            $endTimed = date('Y-m-d H:i:s', $dayEnd);
//            //时间
//
//            //昨天开始
//
//            $year = date("Y");
//            $month = date("m");
//            $day = date("d");
//
//            $dayBegin = mktime(0, 0, 0, $month, $day, $year) - 86400;//當天開始時間戳
//            $dayEnd = mktime(23, 59, 59, $month, $day, $year) - 86400;//當天結束時間戳
//
//            $startTime = date('Y-m-d H:i:s', $dayBegin);
//            $endTime = date('Y-m-d H:i:s', $dayEnd);
//
//            $startTimed = date('Y-m-d H:i:s', $dayBegin);
//            $endTimed = date('Y-m-d H:i:s', $dayEnd);
//
//            //echo $startTimed."<br>";
//            //echo $endTimed."<br>";die;
//
//
//            //昨天结束
//            $otsystem = M('system')->where("SYS_ID ='1'")->find();
//
//            $res = M('user')->where("UE_check ='1' and UE_activeTime > '" . $startTimed . "' and UE_activeTime < '" . $endTimed . "'")->select();
//
//            //dump($otsystem);die; echo $val['ue_accname'];
//            $tjj_tj = 0;
//            $tjj1_tj = 0;
//            $tjj2_tj = 0;
//            $bdj_tj = 0;
//            foreach ($res as $val) {
//                if ($val['ue_accname'] <> '') {
//                    $tjr_1 = M('user')->where("UE_account='" . $val['ue_accname'] . "'")->find();
//                    $tjr_1_he = $tjr_1['ue_money'] + $otsystem['a_kd_zsb'] * 2 * $otsystem['a_ztj'];
//                    M('user')->where("UE_account='" . $tjr_1['ue_account'] . "'")->save(array('UE_money' => $tjr_1_he));
//
//
//                    $record3 ["UG_account"] = $tjr_1['ue_account'];
//                    $record3 ["UG_type"] = 'jb';
//                    $record3 ["UG_money"] = $otsystem['a_kd_zsb'] * 2 * $otsystem['a_ztj'];
//                    $record3 ["UG_allGet"] = $otsystem['a_kd_zsb'] * 2 * $otsystem['a_ztj'];
//                    $record3 ["UG_balance"] = $tjr_1_he;
//                    $record3 ["UG_dataType"] = 'tjj1';
//                    $record3 ["UG_note"] = '推荐奖';
//                    $record3["UG_getTime"] = date('Y-m-d H:i:s', time());
//                    M('userget')->add($record3);
//
//                    $tjj_tj = $tjj_tj + 1;
//
//
//                    if ($tjr_1['ue_accname'] <> '') {
//
//                        $tjr_2 = M('user')->where("UE_account='" . $tjr_1['ue_accname'] . "'")->find();
//                        $tjr_2_he = $tjr_2['ybhe'] + $otsystem['a_kd_zsb'] * 2 * $otsystem['a_ztj2'];
//                        M('user')->where("UE_account='" . $tjr_2['ue_account'] . "'")->save(array('ybhe' => $tjr_2_he));
//
//
//                        $record3 ["UG_account"] = $tjr_2['ue_account'];
//                        $record3 ["UG_type"] = 'yb';
//                        $record3 ["yb"] = $otsystem['a_kd_zsb'] * 2 * $otsystem['a_ztj2'];
//                        $record3 ["yb1"] = $otsystem['a_kd_zsb'] * 2 * $otsystem['a_ztj2'];
//                        $record3 ["ybhe"] = $tjr_2_he;
//                        $record3 ["UG_dataType"] = 'tjj2';
//                        $record3 ["UG_note"] = '间推奖';
//                        $record3["UG_getTime"] = date('Y-m-d H:i:s', time());
//                        M('userget')->add($record3);
//
//                        $tjj1_tj = $tjj1_tj + 1;
//
//                        if ($tjr_2['ue_accname'] <> '') {
//
//                            $tjr_3 = M('user')->where("UE_account='" . $tjr_2['ue_accname'] . "'")->find();
//                            $tjr_3_he = $tjr_3['ybhe'] + $otsystem['a_kd_zsb'] * 2 * $otsystem['a_ztj3'];
//                            M('user')->where("UE_account='" . $tjr_3['ue_account'] . "'")->save(array('ybhe' => $tjr_3_he));
//
//
//                            $record3 ["UG_account"] = $tjr_3['ue_account'];
//                            $record3 ["UG_type"] = 'yb';
//                            $record3 ["yb"] = $otsystem['a_kd_zsb'] * 2 * $otsystem['a_ztj3'];
//                            $record3 ["yb1"] = $otsystem['a_kd_zsb'] * 2 * $otsystem['a_ztj3'];
//                            $record3 ["ybhe"] = $tjr_3_he;
//                            $record3 ["UG_dataType"] = 'tjj3';
//                            $record3 ["UG_note"] = '间间推奖';
//                            $record3["UG_getTime"] = date('Y-m-d H:i:s', time());
//                            M('userget')->add($record3);
//
//                            $tjj2_tj = $tjj2_tj + 1;
//
//                        }
//
//
//                    }
//
//                    dump($tjr_1_he);
//                    die;
//                }
//
//            }
//
//
////     	set_time_limit(10);
////  ob_end_clean();     //在循环输出前，要关闭输出缓冲区
//
////  echo str_pad('',1024);
////  //浏览器在接受输出一定长度内容之前不会显示缓冲输出，这个长度值 IE是256，火狐是1024
////  for($i=1;$i<=100;$i++){
////   echo $i.'<br/>';
////   flush();    //刷新输出缓冲
//
////  }
//
//
//        }
//
//    }

//    public function pin_add()
//    {
//
//
//        $this->display('index/pin_add');
//    }

//    public function pin_add_cl()
//    {
//
//        if (IS_POST) {
//            $data_P = I('post.');
//            //dump($data_P);die;
//
//            $user = M('user')->where(array(
//                UE_account => $data_P['user']
//            ))->find();
//
//            if (!$user) {
//                $this->error('用户 不存在！');
//            } elseif (!preg_match('/^[0-9.]{1,10}$/', $data_P ['sl'])) {
//                $this->error('请填生成数量！');
//            } else {
//                $cgsl = 0;
//                for ($i = 0; $i < $data_P ['sl']; $i++) {
//                    $pin = md5(sprintf("%0" . strlen(9) . "d", mt_rand(0, 99999999999)));
//                    //$pin=0;
//                    if (!M('pin')->where(array('pin' => $pin))->find()) {
//                        $data['user'] = $data_P['user'];
//                        $data['pin'] = $pin;
//                        $data['zt'] = 0;
//                        $data['sc_date'] = date('Y-m-d H:i:s', time());
//                        if (M('pin')->add($data)) {
//                            $cgsl++;
//                        }
//                    }
//                }
//                $this->success('成功添加激活码' . $cgsl . '个');
//            }
//        }
//    }

//    public function pin_list()
//    {
//
//
//        $User = M('pin'); // 實例化User對象
//        $data = I('post.user');
//
//
//        //$map ['UG_dataType'] = array('IN',array('mrfh','tjj','kdj','mrldj','glj'));
//        if (I('get.cz') == 0) {
//            $map['zt'] = 0;
//        }
//        if (I('get.cz') == 1) {
//            $map['zt'] = 1;
//        }
//        if ($data <> '') {
//            $map['user'] = $data;
//        }
//        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
//        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)
//
//        $p = getpage($count, 20);
//
//        $list = $User->where($map)->order('id DESC')->limit($p->firstRow, $p->listRows)->select();
//        $this->assign('list', $list); // 賦值數據集
//        $this->assign('page', $p->show()); // 賦值分頁輸出
//
//
//        $this->display('index/pin_list');
//    }

//    public function pin_del()
//    {
//
//
//        $User = M('user'); // 實例化User對象
//        $data = I('get.id');
//
//
//        if (M('pin')->where(array('id' => $data))->delete()) {
//            $this->success('删除成功!');
//        } else {
//            $this->success('删除失败!');
//        }
//
//
//    }

    /* NOTED BY SKYRIM: 提供帮助、列表 */
    public function tgbz_list()
    {
        $User = M('tgbz'); // 實例化User對象
        $data = I('post.user');

        $this->z_jgbz = $User->sum('jb');
        $this->z_jgbz2 = $User->where(array('zt' => '1'))->sum('jb');
        $this->z_jgbz3 = $User->where(array('zt' => array('neq', 1)))->sum('jb');
        $this->z_jgbz4 = $User->where(array('zt' => array('neq', 1),'tg_status'=>array('eq',1)))->sum('jb');
        //$map ['UG_dataType'] = array('IN',array('mrfh','tjj','kdj','mrldj','glj'));
        
//        $map['zt'] = 0;
//        if (I('get.cz') == 1) {
//            $map['zt'] = 1;
//        }
        if ($data <> '') {
            $map['user'] = $data;
        }
        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)

        $p = getpage($count, 20);

        $list = $User->where($map)->order('date ')->limit($p->firstRow, $p->listRows)->select();
        //dump($list);die;
        $this->assign('list', $list); // 賦值數據集
        $this->assign('page', $p->show()); // 賦值分頁輸出
        
        $this->display('index/tgbz_list');
    }
    public function userlist_topage(){
        if(IS_POST){
            $page=I('post.page');
            if(empty($page)){
                $this->error('非法操作！');
            }
            redirect(U('index/userlist',array('p'=>$page)));
        }
    }
    public function tgbz_topage(){
        if(IS_POST){
            $page=I('post.page');
            if(empty($page)){
                $this->error('非法操作！');
            }
            redirect(U('index/tgbz_list',array('p'=>$page)));
        }
    }
    public function jsbz_topage(){
        if(IS_POST){
            $page=I('post.page');
            if(empty($page)){
                $this->error('非法操作！');
            }
            redirect(U('index/jsbz_list',array('p'=>$page)));
        }
    }
    /* NOTED BY SKYRIM: 接受帮助、列表 */
    public function jsbz_list()
    {


        $User = M('jsbz'); // 實例化User對象
        $data = I('post.user');

        $this->z_jgbz = $User->sum('jb');
        $this->z_jgbz2 = $User->where(array('zt' => '1'))->sum('jb');
        $this->z_jgbz3 = $User->where(array('zt' => array('neq', '1')))->sum('jb');
        $this->z_jgbz4 = $User->where(array('zt' => array('neq', '1'),'js_status'=>array('eq','1')))->sum('jb');

        //$map ['UG_dataType'] = array('IN',array('mrfh','tjj','kdj','mrldj','glj'));

//        $map['zt'] = 0;
//
//        if (I('get.cz') == 1) {
//            $map['zt'] = 1;
//        }
        if ($data <> '') {
            $map['user'] = $data;
        }
        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)

        $p = getpage($count, 20);

        $list = $User->where($map)->order('date ')->limit($p->firstRow, $p->listRows)->select();
        //dump($list);die;
        $this->assign('list', $list); // 賦值數據集
        $this->assign('page', $p->show()); // 賦值分頁輸出

        $this->display('index/jsbz_list');
    }


    public function ppdd_list()
    {


        $User = M('ppdd'); // 實例化User對象
        $pay_user = I('post.pay_user');
        $get_user = I('post.get_user');
        $sub = I('post.sub');
        if($sub==1){
            if (!empty($pay_user)) {
                session('p_user',$pay_user);
            }else{
                session('p_user',null);
            }
            if (!empty($get_user)) {
                $map['g_user'] = $get_user;
                session('g_user',$get_user);
            }else{
                session('g_user',null);
            }
        }

        if(!empty(session('p_user'))){
            $map['p_user'] = session('p_user');
            $this->assign('p_user',$pay_user);
        }
        if(!empty(session('g_user'))){
            $map['g_user'] = session('g_user');
            $this->assign('g_user',$get_user);
        }


        $map['zt'] = array('neq', 2);

        if (I('get.cz') == 1) {
            $map['zt'] = array('eq', 2);;
        }
        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)

        $p = getpage($count, 20);

        $list = $User->where($map)->order('date ')->limit($p->firstRow, $p->listRows)->select();
        //dump($list);die;
        $this->assign('list', $list); // 賦值數據集
        $this->assign('page', $p->show()); // 賦值分頁輸出


        $this->display('index/ppdd_list');
    }


    public function ts1_list()
    {


        $User = M('ppdd'); // 實例化User對象
        $data = I('post.user');


        $map['zt'] = array('neq', 2);
        $map['ts_zt'] = array('eq', 1);;


        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)

        $p = getpage($count, 20);

        $list = $User->where($map)->order('id DESC')->limit($p->firstRow, $p->listRows)->select();
        //dump($list);die;
        $this->assign('list', $list); // 賦值數據集
        $this->assign('page', $p->show()); // 賦值分頁輸出


        $this->display('index/ts1_list');
    }


//    public function ts3_list()
//    {
//
//
//        $User = M('ppdd'); // 實例化User對象
//        $data = I('post.user');
//
//
//        $map['zt'] = array('neq', 2);
//        $map['ts_zt'] = array('eq', 2);;
//
//
//        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
//        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)
//
//        $p = getpage($count, 20);
//
//        $list = $User->where($map)->order('id DESC')->limit($p->firstRow, $p->listRows)->select();
//        //dump($list);die;
//        $this->assign('list', $list); // 賦值數據集
//        $this->assign('page', $p->show()); // 賦值分頁輸出
//
//
//        $this->display('index/ts3_list');
//    }
//
//    public function ts2_list()
//    {
//
//
//        $User = M('ppdd'); // 實例化User對象
//        $data = I('post.user');
//
//
//        $map['zt'] = array('neq', 2);
//        $map['ts_zt'] = array('eq', 3);;
//
//
//        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
//        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)
//
//        $p = getpage($count, 20);
//
//        $list = $User->where($map)->order('id DESC')->limit($p->firstRow, $p->listRows)->select();
//        //dump($list);die;
//        $this->assign('list', $list); // 賦值數據集
//        $this->assign('page', $p->show()); // 賦值分頁輸出
//
//
//        $this->display('index/ts2_list');
//    }


//    public function ts1_list_cl()
//    {
//
//        $ppddxx = M('ppdd')->where(array('id' => I('get.id')))->find();
//        M('tgbz')->where(array('id' => $ppddxx['p_id']))->save(array('zt' => 0, 'qr_zt' => 0));
//        M('jsbz')->where(array('id' => $ppddxx['g_id']))->save(array('zt' => 0, 'qr_zt' => 0));
//        M('ppdd')->where(array('id' => I('get.id')))->delete();
//        $this->success('重新匹配成功');
//    }
//
//
//    public function ts3_list_cl()
//    {
//
//        $ppddxx = M('ppdd')->where(array('id' => I('get.id')))->find();
//        M('tgbz')->where(array('id' => $ppddxx['p_id']))->save(array('zt' => 0, 'qr_zt' => 0));
//        M('jsbz')->where(array('id' => $ppddxx['g_id']))->save(array('zt' => 0, 'qr_zt' => 0));
//        M('ppdd')->where(array('id' => I('get.id')))->delete();
//        M('user_jj')->where(array('r_id' => $ppddxx['id']))->delete();
//        M('user_jl')->where(array('r_id' => $ppddxx['id']))->delete();
//        $this->success('重新匹配成功');
//    }
//
//
//    public function ts2_list_cl()
//    {
//
//        $ppddxx = M('ppdd')->where(array('id' => I('get.id')))->find();
//        M('tgbz')->where(array('id' => $ppddxx['p_id']))->save(array('zt' => 0, 'qr_zt' => 0));
//        M('jsbz')->where(array('id' => $ppddxx['g_id']))->save(array('zt' => 0, 'qr_zt' => 0));
//        M('ppdd')->where(array('id' => I('get.id')))->delete();
//        $this->success('重新匹配成功');
//    }


    public function tgbz_list_sd()
    {
        if (I('get.id') <> '') {
            if (!stristr($_SERVER['HTTP_REFERER'], ACTION_NAME))//初始化选中值
            {
                $_SESSION['check_p']['check_id'] = ",";
                $_SESSION['check_p']['check_money'] = 0;
            }
            $tgbzuser = M('tgbz')->where(array('id' => I('get.id')))->find();
            $this->tgbzuser = $tgbzuser;
            if ($tgbzuser['zffs1'] == '1') {
                $zffs1 = '1';
            } else {
                $zffs1 = '5';
            }
            if ($tgbzuser['zffs2'] == '1') {
                $zffs2 = '1';
            } else {
                $zffs2 = '5';
            }
            if ($tgbzuser['zffs3'] == '1') {
                $zffs3 = '1';
            } else {
                $zffs3 = '5';
            }
            $User = M('jsbz'); // 實例化User對象
            $data = I('post.user');


            $where['zffs1'] = $zffs1;
            $where['zffs2'] = $zffs2;
            $where['zffs3'] = $zffs3;
            $where['_logic'] = 'or';
            $map['_complex'] = $where;
            $map['zt'] = 0;

            $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
            //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)

            $p = getpage($count, 20);

            $list = $User->where($map)->order('date ')->limit($p->firstRow, $p->listRows)->select();
            //dump($list);die;
            $this->assign('list', $list); // 賦值數據集
            $this->assign('page', $p->show()); // 賦值分頁輸出

            //已选择的数据
            if (!empty($_SESSION['check_p']['check_money'])) {
                $this->assign('check_array', explode(",", $_SESSION['check_p']['check_id']));
            }
            $this->assign('check_id', $_SESSION['check_p']['check_id']);
            $this->assign('check_money', $_SESSION['check_p']['check_money']);


            $this->display('index/tgbz_list_sd');
        }
    }

    //记录选中的_SESSION
//    public function tgbz_list_sd_cookie()
//    {
//        $_SESSION['check_p']['check_id'] = I('get.id');
//        $_SESSION['check_p']['check_money'] = I('get.money');
//    }

//    public function jsbz_list_sd()
//    {
//        if (I('get.id') <> '') {
//            if (!stristr($_SERVER['HTTP_REFERER'], ACTION_NAME))//初始化选中值
//            {
//                $_SESSION['check_p']['check_id'] = ",";
//                $_SESSION['check_p']['check_money'] = 0;
//            }
//            $tgbzuser = M('jsbz')->where(array('id' => I('get.id')))->find();
//            $this->tgbzuser = $tgbzuser;
//            if ($tgbzuser['zffs1'] == '1') {
//                $zffs1 = '1';
//            } else {
//                $zffs1 = '5';
//            }
//            if ($tgbzuser['zffs2'] == '1') {
//                $zffs2 = '1';
//            } else {
//                $zffs2 = '5';
//            }
//            if ($tgbzuser['zffs3'] == '1') {
//                $zffs3 = '1';
//            } else {
//                $zffs3 = '5';
//            }
//            $User = M('tgbz'); // 實例化User對象
//            $data = I('post.user');
//
//
//            $where['zffs1'] = $zffs1;
//            $where['zffs2'] = $zffs2;
//            $where['zffs3'] = $zffs3;
//            $where['_logic'] = 'or';
//            $map['_complex'] = $where;
//            $map['zt'] = 0;
//
//            $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
//            //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)
//
//            $p = getpage($count, 20);
//
//            $list = $User->where($map)->order('date ')->limit($p->firstRow, $p->listRows)->select();
//            //dump($list);die;
//            $this->assign('list', $list); // 賦值數據集
//            $this->assign('page', $p->show()); // 賦值分頁輸出
//            //已选择的数据
//            if (!empty($_SESSION['check_p']['check_money'])) {
//                $this->assign('check_array', explode(",", $_SESSION['check_p']['check_id']));
//            }
//            $this->assign('check_id', $_SESSION['check_p']['check_id']);
//            $this->assign('check_money', $_SESSION['check_p']['check_money']);
//
//
//            $this->display('index/jsbz_list_sd');
//        }
//    }
//
//
//    public function tgbz_list_sd_cl()
//    {
//        $data = I('post.');
//        $arr = explode(',', I('post.arrid'));
//        // deleted by skyrim
//        // purpose: arr isn't money
//        // version: 7
//        // // added by skyrim
//        // // purpose: check money in range
//        // // version: 4
//        // $settings = include( dirname( APP_PATH ) . '/User/Home/Conf/settings.php' );
//        // var_dump( $arr );
//        // foreach( $arr as $q ){
//        // 	var_dump( $q  );
//        // 	if( $settings['supply_money_upper_limit'] < $q || $q < $settings['supply_money_lower_limit'] ){
//        // 		echo ';金额不在范围内';
//        // 	//	$this->error('金额不在范围内!');
//        //
//        // 		return;
//        // 	}
//        // }
//        // // added ends
//        // deleted ends
//        //dump($arr);
//        $p_user = M('tgbz')->where(array('id' => $data['pid']))->find();
//        global $p_id2;
//        $p_id2 = $data['pid'];
//        if ($data['arrzs'] <> $data['jb']) {
//            $this->success('匹配金额不等!');
//        } else {
//            $pipeits = 0;
//
//
//            foreach ($arr as $val) {
//                $g_user = M('jsbz')->where(array('id' => $val))->find();
//                //echo $g_user['user'].'<br>';
//                //echo $p_user['user'].'<br>';die;
//                if ($g_user['user'] == $p_user['user']) {
//                    $sfxd = '1';
//                    break;
//                } else {
//                    $sfxd = '0';
//                }
//            }
//
//            if ($sfxd == '0') {
//
//                foreach ($arr as $val) {
//
//                    if ($val <> '') {
//                        //$p_id2充值ID ,$val提现ID
//
//                        if (ppdd_add($p_id2, $val)) {
//                            $pipeits++;
//                            M('tgbz')->where(array('id' => $data['pid']))->setInc('cf_ds', 1);
//                        }
//                    }
//                }
//            } else {
//                $usercf = '用户名重复';
//            }
//            if ($pipeits <> '0') {
//                $p_user1 = M('tgbz')->where(array('id' => $data['pid']))->find();
//                $tj_ppdd = M('ppdd')->where(array('p_id' => $p_user1['id']))->select();
//
//                foreach ($tj_ppdd as $value) {
//
//                    $data2['zffs1'] = $p_user1['zffs1'];
//                    $data2['zffs2'] = $p_user1['zffs2'];
//                    $data2['zffs3'] = $p_user1['zffs3'];
//                    $data2['user'] = $p_user1['user'];
//                    $data2['jb'] = $value['jb'];
//                    $data2['user_nc'] = $p_user1['user_nc'];
//                    $data2['user_tjr'] = $p_user1['user_tjr'];
//                    $data2['date'] = $p_user1['date'];
//                    $data2['zt'] = $p_user1['zt'];
//                    $data2['qr_zt'] = $p_user1['qr_zt'];
//                    $varid = M('tgbz')->add($data2);
//
//                    M('ppdd')->where(array('id' => $value['id']))->save(array('p_id' => $varid));
//
//                }
//
//                M('tgbz')->where(array('id' => $data['pid']))->delete();
//                M('user_jj')->where(array('tgbz_id' => $data['pid']))->save(array('zt' => 3));
//            }
//            $_SESSION['check_p']['check_id'] = ",";
//            $_SESSION['check_p']['check_money'] = 0;
//
//            $this->success('匹配成功!拆分成' . $pipeits . '条订单,' . $usercf . '!');
//        }
//    }


    /* NOTED BY SKYRIM: 接受帮助、手动处理*/
//    public function jsbz_list_sd_cl()
//    {
//        $data = I('post.');
//        $arr = explode(',', I('post.arrid'));//充值IP
//        // deleted by skyrim
//        // purpose: arr isn't money
//        // version: 7
//        // // added by skyrim
//        // // purpose: check money in range
//        // // version: 4
//        // $settings = include( dirname( APP_PATH ) . '/User/Home/Conf/settings.php' );
//        //
//        // foreach( $arr as $q ){
//        // 	if( $settings['supply_money_upper_limit'] < $q || $q < $settings['supply_money_lower_limit'] ){
//        // 		$this->error('金额不在范围内!');
//        //
//        // 		return;
//        // 	}
//        // }
//        // // added ends
//        // deleted ends
//        //dump($arr);
//        $p_user = M('jsbz')->where(array('id' => $data['pid']))->find();//提现订单
//        global $p_id2;
//        $p_id2 = $data['pid'];//提现ID
//        if ($data['arrzs'] <> $data['jb']) {
//            $this->success('匹配金额不等!');
//        } else {
//            $pipeits = 0;
//
//
//            foreach ($arr as $val) {
//                $g_user = M('tgbz')->where(array('id' => $val))->find();
//                //echo $g_user['user'].'<br>';
//                //echo $p_user['user'].'<br>';die;
//                if ($g_user['user'] == $p_user['user']) {
//                    $sfxd = '1';
//                    break;
//                } else {
//                    $sfxd = '0';
//                }
//
//            }
//
//            if ($sfxd == '0') {
//
//                foreach ($arr as $val) {
//
//                    if ($val <> '') {
//                        //$val充值人  ,$p_id2提现人
//                        if (ppdd_add2($val, $p_id2)) {
//                            $pipeits++;
//                            //M('jsbz')->where(array('id'=>$data['pid']))->setInc('cf_ds',1);
//                        }
//                    }
//                }
//            } else {
//                $usercf = '用户名重复';
//            }
//
//
//            //拆分充值
//            if ($pipeits <> '0') {
//
//                $p_user1 = M('jsbz')->where(array('id' => $data['pid']))->find();
//                $tj_ppdd = M('ppdd')->where(array('g_id' => $p_user1['id']))->select();
//
//                foreach ($tj_ppdd as $value) {
//
//                    $data2['zffs1'] = $p_user1['zffs1'];
//                    $data2['zffs2'] = $p_user1['zffs2'];
//                    $data2['zffs3'] = $p_user1['zffs3'];
//                    $data2['user'] = $p_user1['user'];
//                    $data2['jb'] = $value['jb'];
//                    $data2['user_nc'] = $p_user1['user_nc'];
//                    $data2['user_tjr'] = $p_user1['user_tjr'];
//                    $data2['date'] = $p_user1['date'];
//                    $data2['zt'] = $p_user1['zt'];
//                    $data2['qr_zt'] = $p_user1['qr_zt'];
//                    $varid = M('jsbz')->add($data2);
//
//                    M('ppdd')->where(array('id' => $value['id']))->save(array('g_id' => $varid));
//
//                }
//
//                M('jsbz')->where(array('id' => $data['pid']))->delete();
//            }
//
//            //拆分充值
//
//
//            $_SESSION['check_p']['check_id'] = ",";
//            $_SESSION['check_p']['check_money'] = 0;
//
//
//            $this->success('匹配成功!拆分成' . $pipeits . '条订单,' . $usercf . '!');
//        }
//    }


//    public function zdpp_cl()
//    {
//
//        $tgbz_user = M('tgbz')->where(array('zt' => '0'))->select();
//        $pipeits = 0;
//        foreach ($tgbz_user as $val) {
//
//            //dump();die;
//            $jsbz_list = tgbz_zd_cl($val['id']);
//            foreach ($jsbz_list as $val1) {
//                //echo $val['jb'].'--<br>';
//                //echo $val1['jb'].'<br>';
//
//                if ($val['jb'] == $val1['jb'] && $val['user'] <> $val1['user']) {//如果匹配成功处理
//                    if (ppdd_add($val['id'], $val1['id'])) {
//                        $pipeits++;
//                        M('tgbz')->where(array('id' => $val['id']))->save(array('cf_ds' => '1'));
//                        break;
//                    }
//                }
//
//            }
//
//        }
//        echo('成功匹配订单' . $pipeits . '条');
//
//    }
//
//    public function zdpp_cl2()
//    {
//
//
//        $tgbz_user = M('tgbz')->where(array('zt' => '0'))->select();
//        $pipeits = 0;
//        foreach ($tgbz_user as $val) {
//
//            //dump();die;
//            $jsbz_list = tgbz_zd_cl($val['id']);
//            $i = '0';
//            foreach ($jsbz_list as $val1) {
//                if ($val['user'] <> $val1['user']) {
//                    $jsbz_list2[$i] = $val1['id'];
//                    $i++;
//                }
//            }
//            //echo $val['jb'];die;
//            //dump($jsbz_list2);die;
//
//            $xypipeije = $val['jb'];
//            $data = $jsbz_list2;
//            $tj = count($data);
//            //echo $tj;die;
//            $sf_tcpp = '0';
//            for ($b = 0; $b < $tj; $b++) {
//                if ($sf_tcpp == '1') {
//                    break;
//                }
//                $tj_j = $tj - 1;
//                //echo '===========<br>';
//                for ($i = 0; $i < $tj; $i++) {
//                    if ($b < $i) {
//                        $pipeihe = jsbz_jb($data[$b]) + jsbz_jb($data[$tj_j]);
//                        if ($pipeihe == $xypipeije) {
//                            $g_a = $data[$b];
//                            $g_b = $data[$tj_j];
//                            $sf_tcpp = '1';
//                            break;
//                        }
//
//
//                        $tj_j--;
//                    }
//                }
//            }
//            //echo $val['id'].'主<br>';
//            //echo $g_a.'<br>';
//            //echo $g_b.'<br>';
//            if ($g_a <> '' && $g_b <> '') {
//
//                if (ppdd_add($val['id'], $g_a) && ppdd_add($val['id'], $g_b)) {
//                    $pipeits++;
//                    M('tgbz')->where(array('id' => $val['id']))->save(array('cf_ds' => '1'));
//                    echo '主ID:' . $val['id'] . '金币:' . $val['jb'] . '=副A:' . $g_a . '金币:' . jsbz_jb($g_a) . '+副B:' . $g_b . '金币:' . jsbz_jb($g_b) . '<br>';
//                }
//            }
//
//            //拆分充值
//            if ($sf_tcpp == '1') {
//                $p_user1 = M('tgbz')->where(array('id' => $val['id']))->find();
//                $tj_ppdd = M('ppdd')->where(array('p_id' => $p_user1['id']))->select();
//
//                foreach ($tj_ppdd as $value) {
//
//                    $data2['zffs1'] = $p_user1['zffs1'];
//                    $data2['zffs2'] = $p_user1['zffs2'];
//                    $data2['zffs3'] = $p_user1['zffs3'];
//                    $data2['user'] = $p_user1['user'];
//                    $data2['jb'] = $value['jb'];
//                    $data2['user_nc'] = $p_user1['user_nc'];
//                    $data2['user_tjr'] = $p_user1['user_tjr'];
//                    $data2['date'] = $p_user1['date'];
//                    $data2['zt'] = $p_user1['zt'];
//                    $data2['qr_zt'] = $p_user1['qr_zt'];
//                    $varid = M('tgbz')->add($data2);
//
//                    M('ppdd')->where(array('id' => $value['id']))->save(array('p_id' => $varid));
//
//                }
//
//                M('tgbz')->where(array('id' => $val['id']))->delete();
//
//            }
//            //拆分充值
//
//        }
//        echo('成功匹配订单' . $pipeits . '条');
//
//
//    }

//    public function tgbz_list_cf()
//    {
//
//
//        $User = M('tgbz'); // 實例化User對象
//        $data = I('post.user');
//
//        $this->z_jgbz = $User->sum('jb');
//        $this->z_jgbz2 = $User->where(array('qr_zt' => '1'))->sum('jb');
//        $this->z_jgbz3 = $User->where(array('qr_zt' => array('neq', '1')))->sum('jb');
//        //$map ['UG_dataType'] = array('IN',array('mrfh','tjj','kdj','mrldj','glj'));
//
//        $map['zt'] = 0;
//
//        if (I('get.cz') == 1) {
//            $map['zt'] = 1;
//        }
//        if ($data <> '') {
//            $map['user'] = $data;
//        }
//        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
//        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)
//
//        $p = getpage($count, 20);
//
//        $list = $User->where($map)->order('id')->limit($p->firstRow, $p->listRows)->select();
//        //dump($list);die;
//        $this->assign('list', $list); // 賦值數據集
//        $this->assign('page', $p->show()); // 賦值分頁輸出
//
//
//        $this->display('index/tgbz_list_cf');
//    }
//
//    public function jsbz_list_cf()
//    {
//
//
//        $User = M('jsbz'); // 實例化User對象
//        $data = I('post.user');
//
//        $this->z_jgbz = $User->sum('jb');
//        $this->z_jgbz2 = $User->where(array('qr_zt' => '1'))->sum('jb');
//        $this->z_jgbz3 = $User->where(array('qr_zt' => array('neq', '1')))->sum('jb');
//        //$map ['UG_dataType'] = array('IN',array('mrfh','tjj','kdj','mrldj','glj'));
//
//        $map['zt'] = 0;
//
//        if (I('get.cz') == 1) {
//            $map['zt'] = 1;
//        }
//        if ($data <> '') {
//            $map['user'] = $data;
//        }
//        $count = $User->where($map)->count(); // 查詢滿足要求的總記錄數
//        //$page = new \Think\Page ( $count, 3 ); // 實例化分頁類 傳入總記錄數和每頁顯示的記錄數(25)
//
//        $p = getpage($count, 20);
//
//        $list = $User->where($map)->order('id')->limit($p->firstRow, $p->listRows)->select();
//        //dump($list);die;
//        $this->assign('list', $list); // 賦值數據集
//        $this->assign('page', $p->show()); // 賦值分頁輸出
//
//
//        $this->display('index/jsbz_list_cf');
//    }
//
//    public function tgbz_list_cf_cl()
//    {
//        $data = I('post.');
//        $p_user = M('tgbz')->where(array('id' => $data['pid']))->find();
//        if (!preg_match('/^[0-9,]{1,100}$/', I('post.arrid'))) {
//            $this->error('格式不对!');
//            die;
//        }
//        $arr = explode(',', I('post.arrid'));
//        //dump($arr);
//        if (array_sum($arr) <> $p_user['jb']) {
//            $this->error('拆分金额不对!');
//            die;
//        }
//        // added by skyrim
//        // purpose: check money in range
//        // version: 4
//        $settings = include(dirname(APP_PATH) . '/User/Home/Conf/settings.php');
//
//        foreach ($arr as $q) {
//            if ($settings['supply_money_upper_limit'] < $q || $q < $settings['supply_money_lower_limit']) {
//                $this->error('金额不在范围内!');
//
//                return;
//            }
//        }
//        // added ends
//
//
//        $p_user1 = M('tgbz')->where(array('id' => $data['pid']))->find();
//
//        $pipeits = 0;
//        foreach ($arr as $value) {
//            if ($value <> '') {
//                $data2['zffs1'] = $p_user1['zffs1'];
//                $data2['zffs2'] = $p_user1['zffs2'];
//                $data2['zffs3'] = $p_user1['zffs3'];
//                $data2['user'] = $p_user1['user'];
//                $data2['jb'] = $value;
//                $data2['user_nc'] = $p_user1['user_nc'];
//                $data2['user_tjr'] = $p_user1['user_tjr'];
//                $data2['date'] = $p_user1['date'];
//                $data2['zt'] = $p_user1['zt'];
//                $data2['qr_zt'] = $p_user1['qr_zt'];
//                $varid = M('tgbz')->add($data2);
//                $pipeits++;
//            }
//
//
//        }
//
//        M('tgbz')->where(array('id' => $data['pid']))->delete();
//
//
//        $this->success('匹配成功!拆分成' . $pipeits . '条订单!');
//    }
//
//    public function jsbz_list_cf_cl()
//    {
//        $data = I('post.');
//        $p_user = M('jsbz')->where(array('id' => $data['pid']))->find();
//        if (!preg_match('/^[0-9,]{1,100}$/', I('post.arrid'))) {
//            $this->error('格式不对!');
//            die;
//        }
//        $arr = explode(',', I('post.arrid'));
//        //dump($arr);
//        if (array_sum($arr) <> $p_user['jb']) {
//            $this->error('拆分金额不对!');
//            die;
//        }
//        // added by skyrim
//        // purpose: check money in range
//        // version: 4
//        $settings = include(dirname(APP_PATH) . '/User/Home/Conf/settings.php');
//
//        foreach ($arr as $q) {
//            if ($settings['supply_money_upper_limit'] < $q || $q < $settings['supply_money_lower_limit']) {
//                $this->error('金额不在范围内!');
//
//                return;
//            }
//        }
//        // added ends
//
//
//        $p_user1 = M('jsbz')->where(array('id' => $data['pid']))->find();
//
//        $pipeits = 0;
//        foreach ($arr as $value) {
//            if ($value <> '') {
//                $data2['zffs1'] = $p_user1['zffs1'];
//                $data2['zffs2'] = $p_user1['zffs2'];
//                $data2['zffs3'] = $p_user1['zffs3'];
//                $data2['user'] = $p_user1['user'];
//                $data2['jb'] = $value;
//                $data2['user_nc'] = $p_user1['user_nc'];
//                $data2['user_tjr'] = $p_user1['user_tjr'];
//                $data2['date'] = $p_user1['date'];
//                $data2['zt'] = $p_user1['zt'];
//                $data2['qr_zt'] = $p_user1['qr_zt'];
//                $varid = M('jsbz')->add($data2);
//                $pipeits++;
//            }
//
//
//        }
//
//        M('jsbz')->where(array('id' => $data['pid']))->delete();
//
//
//        $this->success('匹配成功!拆分成' . $pipeits . '条订单!');
//    }


    public function settings($templ = '')
        {
            $settings = include(dirname(APP_PATH) . '/User/Home/Conf/settings.php');

            if (IS_POST) {
                foreach ($_POST['jl_share'] as $k => $v) {
                    $_POST['jl_share'][$k] = floatval($v) / 100.0;
                }
                foreach ($_POST['masses_share'] as $k => $v) {
                    $_POST['masses_share'][$k] = floatval($v) / 100.0;
                }

                foreach ($settings as $k => $v) {
                    if (isset($_POST[$k])) {
                        $settings[$k] = $_POST[$k];
                    }
                }

                $file_length = file_put_contents(dirname(APP_PATH) . '/User/Home/Conf/settings.php', '<?php return ' . var_export($settings, true) . '; ?>');

                if ($file_length) {
                    $this->success('保存成功！');
                } else {
                    $this->error('保存失败！请检查文件权限');
                }
                return;
            }

            foreach ($settings as $k => $v) {
                if ($k == 'jl_share' || $k == 'masses_share') {
                    foreach ($v as $kk => $vv) {
                        $v[$kk] = floatval($vv) * 100;
                    }
                }

                $this->assign($k, $v);
            }
            $this->assign('settings', $settings);

            $this->display($templ);
        }

}